00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00031 require_once (PATH_TO_ROOT."common/classes/class.modulautomation.inc.php");
00032 require_once (PATH_TO_ROOT."roleplay/classes/class.roleartefacts.inc.php");
00033 class MessagingAutomation extends ModulAutomation {
00040 function MessagingAutomation() {
00041 parent::ModulAutomation();
00042 $this->info = "Private Nachrichten";
00043 $this->necessaryDatabaseTable = "messaging_inbox";
00044 }
00052 function dailyWork() {
00053 global $db, $EZSQL_ERROR, $settings;
00054 if ($settings["pm_days_to_delete_messages"] > 0) {
00055 $time = time() -($settings["pm_days_to_delete_messages"]*24*3600);
00056
00057 $errorCount = count($EZSQL_ERROR);
00058 $toDelete = $db->get_col("SELECT ID FROM messaging_inbox WHERE date < $time AND isRead = 1 AND isArchived = 0");
00059 if (!empty($toDelete)) {
00060 RoleArtefacts::deleteItem(PM, $toDelete);
00061 $db->query("DELETE FROM messaging_inbox WHERE date < $time AND isRead = 1 AND isArchived = 0");
00062 }
00063 if (count($EZSQL_ERROR) > $errorCount) {
00064 $this->error("Fehler beim Aufräumen des Posteingangs:\n".print_r($EZSQL_ERROR[$errorCount], true));
00065 } else {
00066 $this->writeToLogfile($db->rows_affected." alte empfangene Nachrichten gelöscht.");
00067 }
00068 $errorCount = count($EZSQL_ERROR);
00069 $db->query("DELETE FROM messaging_outbox WHERE date < $time AND isArchived = 0");
00070 if (count($EZSQL_ERROR) > $errorCount) {
00071 $this->error("Fehler beim Aufräumen der gesendeten Nachrichten:\n".print_r($EZSQL_ERROR[$errorCount], true));
00072 } else {
00073 $this->writeToLogfile($db->rows_affected." alte gesendete Nachrichten gelöscht.");
00074 }
00075 if (!empty($this->errorString)) return false;
00076 }
00077 return true;
00078 }
00085 function deleteUser($userID) {
00086 global $db, $EZSQL_ERROR;
00087 $errorCount = count($EZSQL_ERROR);
00088 $db->query("DELETE FROM messaging_inbox WHERE userID='$userID'");
00089 if (count($EZSQL_ERROR) > $errorCount) {
00090 $this->error("Fehler beim Löschen der empfangenen Nachrichten:\n".print_r($EZSQL_ERROR[$errorCount], true));
00091 } else {
00092 $this->writeToLogfile($db->rows_affected." empfangene Nachricht(en) gelöscht.");
00093 }
00094 $errorCount = count($EZSQL_ERROR);
00095 $db->query("UPDATE messaging_inbox SET authorID=3 WHERE authorID=".$userID);
00096 if (count($EZSQL_ERROR) > $errorCount) {
00097 $this->error("Fehler beim Aktualisieren der empfangenen Nachrichten anderer Benutzer:\n".print_r($EZSQL_ERROR[$errorCount], true));
00098 } else {
00099 $this->writeToLogfile($db->rows_affected." empfangene Nachricht(en) anderer Benutzer aktualisiert.");
00100 }
00101 $errorCount = count($EZSQL_ERROR);
00102 $db->query("DELETE FROM messaging_outbox WHERE userID=".$userID);
00103 if (count($EZSQL_ERROR) > $errorCount) {
00104 $this->error("Fehler beim Löschen der gesendeten Nachrichten:\n".print_r($EZSQL_ERROR[$errorCount], true));
00105 } else {
00106 $this->writeToLogfile($db->rows_affected." gesendete Nachricht(en) gelöscht.");
00107 }
00108 $errorCount = count($EZSQL_ERROR);
00109 $messages = $db->get_results("SELECT ID, recipientID FROM messaging_outbox WHERE recipientID LIKE '%$userID;%'");
00110 if (count($EZSQL_ERROR) > $errorCount) {
00111 $this->error("Fehler beim Ermitteln der an den Benutzer gesendeten Nachrichten:\n".print_r($EZSQL_ERROR[$errorCount], true));
00112 } else {
00113 $count = 0;
00114 if ($db->num_rows) {
00115 foreach($messages as $message) {
00116 $recipients = explode(";", $message->recipientID);
00117 $count = count($recipients);
00118 for ($i = 0 ; $i < $count ; $i++) {
00119 if ($recipients[$i] == $userID) {
00120 $recipients[$i] = 3;
00121 }
00122 }
00123 $recipients = implode(";", $recipients);
00124 if ($recipients != $message->recipientID) {
00125 $errorCount = count($EZSQL_ERROR);
00126 $db->query("UPDATE messaging_outbox SET recipientID='$recipients' WHERE ID=$message->ID");
00127 if (count($EZSQL_ERROR) > $errorCount) {
00128 $this->error("Fehler beim Aktualisieren der Nachricht $message->ID:\n".print_r($EZSQL_ERROR[$errorCount], true));
00129 } else {
00130 $count++;
00131 }
00132 }
00133 }
00134 }
00135 $this->writeToLogfile("$count gesendete Nachricht(en) aktualisiert.");
00136 }
00137 $errorCount = count($EZSQL_ERROR);
00138 $db->query("DELETE FROM messaging_buddylist WHERE userID=$userID OR buddyID=$userID");
00139 if (count($EZSQL_ERROR) > $errorCount) {
00140 $this->error("Fehler beim Löschen der Buddies:\n".print_r($EZSQL_ERROR[$errorCount], true));
00141 } else {
00142 $this->writeToLogfile($db->rows_affected." Buddies gelöscht.");
00143 }
00144 if (!empty($this->errorString)) return false;
00145 return true;
00146 }
00147 }
00148 ?>